﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunitySystem.Assert;
using CommunitySystem.PublicOfficialSelectionService;
using CommunitySystem.Views;
using EHR.Common;
using org.in2bits.MyXls;

namespace CommunitySystem
{
    public partial class PublicOfficialSelectionControl : UserControl
    {
        private int ExamID = -1;
        private PublicOfficialSelectionService.PublicOfficialSelectionServiceClient Client1 = new PublicOfficialSelectionService.PublicOfficialSelectionServiceClient();
        PublicOfficialSelectionService.PublicOfficialSelectionModel RoleModel = new PublicOfficialSelectionService.PublicOfficialSelectionModel();
        private EmpbasicService.EmpBasicServiceClient Client = new EmpbasicService.EmpBasicServiceClient();
        private ObservableCollection<PublicOfficialSelectionService.PublicOfficialSelectionModel> selectedempmodel =
            new ObservableCollection<PublicOfficialSelectionService.PublicOfficialSelectionModel>();
        private int OrgID = 0;
        public NavMoveSwitch Nav { get; set; }
        private string juese = "";
        private ObservableCollection<PublicOfficialInfo> poi =
            new ObservableCollection<PublicOfficialInfo>();
        public PublicOfficialSelectionControl()
        {
            //实现的思路应该是根据登录人的ID，找到对应的OrgID
            InitializeComponent();
            selectedempmodel.Clear();
            _gridClickManagerXQ = new MouseClickManager(DGRole, 300);
            _gridClickManagerXQ.DoubleClick += new System.Windows.Input.MouseButtonEventHandler(_gridClickManagerXQ_DoubleClick);
            Client.GetDengLuJueSeCompleted += new EventHandler<EmpbasicService.GetDengLuJueSeCompletedEventArgs>(Client_GetDengLuJueSeCompleted);
            Client.GetDengLuJueSeAsync(Session.LoginUser.LoginName);

            //if (Session.LoginUser.UserID == 17)//admin登录
            //{
            //    TreeOfLife.Visibility = System.Windows.Visibility.Visible;
            //    colLeft.Width = new GridLength(265);
            //    colSplit.Width = new GridLength(10);
            //}
            //else
            //{
            //    TreeOfLife.Visibility = System.Windows.Visibility.Collapsed;
            //    colLeft.Width = new GridLength(0);
            //    colSplit.Width = new GridLength(0);
            //}
            if (TreeOfLife.ItemsSource != null) TreeOfLife.ItemsSource = null;
            Client.GetOrgForHRModelCompleted += new EventHandler<EmpbasicService.GetOrgForHRModelCompletedEventArgs>(Client_GetOrgForHRModelCompleted);
            Client.GetOrgForHRModelAsync(0);
            //for (int i = DateTime.Today.Year; i > DateTime.Today.Year - 10; i--)
            //{
            //    ComboBoxItem cbi = new ComboBoxItem();
            //    cbi.Content = i.ToString();
            //    cbi.Tag = i;
            //    nian.Items.Add(cbi);
            //}
            //nian.SelectedIndex = 0;
            Client1.GetPublicOfficialInfo1Completed += new EventHandler<GetPublicOfficialInfo1CompletedEventArgs>(Client1_GetPublicOfficialInfo1Completed);
            Client1.GetPublicOfficialInfo1Async(1, 0);
            //DGRole.FrozenColumnCount = 4;


        }
        void Client1_GetPublicOfficialInfo1Completed(object sender, GetPublicOfficialInfo1CompletedEventArgs e)
        {
            nian.ItemsSource = null;
            poi = e.Result;
            ObservableCollection<PublicOfficialInfo> poi1 = new ObservableCollection<PublicOfficialInfo>();
            #region  old
            //foreach (PublicOfficialInfo p in poi)
            //{
            //    if (p.Status == 1) poi1.Add(p);
            //}
            //foreach (PublicOfficialInfo p in poi)
            //{
            //    if (p.Status == 2) poi1.Add(p);
            //}
            //foreach (PublicOfficialInfo p in poi)
            //{
            //    if (p.Status == 0) poi1.Add(p);
            //}
            #endregion
            foreach (PublicOfficialInfo p in poi)
            {
            
                if (!p.IsLocked.Value) poi1.Add(p);
            }
          
            //if (poi.Where(p => p.Status == 1 || p.Status == 2).FirstOrDefault() != null) poi1.Add(poi.Where(p => p.Status == 1 || p.Status == 2).FirstOrDefault());

            if (poi1.Count > 0 && poi1[0] != null)
            {
                nian.ItemsSource = poi1;
                if (poi1.Count > 0) nian.SelectedIndex = 0;
            }
            Load();
        }

        private int kaoshistatus = 0;
        private int kaoshitype = 0;
        void gangwei_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (((ComboBox)sender).SelectedItem != null)
            {
                ExamID = ((CommunitySystem.PublicOfficialSelectionService.PublicOfficialInfo)((((ComboBox)sender).SelectedItem))).ID;
                kaoshitype =
                    ((CommunitySystem.PublicOfficialSelectionService.PublicOfficialInfo)
                     ((((ComboBox)sender).SelectedItem))).Type;
                kaoshistatus =
                    ((CommunitySystem.PublicOfficialSelectionService.PublicOfficialInfo)
                     ((((ComboBox)sender).SelectedItem))).Status;
            }
            else ExamID = 0;
        }
        void Client_GetDengLuJueSeCompleted(object sender, EmpbasicService.GetDengLuJueSeCompletedEventArgs e)
        {
            juese = e.Result;
            if (e.Result != "人事干部")
            {
                TreeOfLife.Visibility = System.Windows.Visibility.Visible;
                colLeft.Width = new GridLength(265);
                colSplit.Width = new GridLength(10);
                CheckData.Visibility = System.Windows.Visibility.Visible;
                TuiData.Visibility = System.Windows.Visibility.Visible;
                FaBuData.Visibility = System.Windows.Visibility.Visible;
                tiaomu.Visibility = System.Windows.Visibility.Visible;
                JZXData.Visibility = System.Windows.Visibility.Visible;
                XDData.Visibility = System.Windows.Visibility.Visible;
                CancelCheckData.Visibility = System.Windows.Visibility.Visible;
                SuoData.Visibility = System.Windows.Visibility.Visible;
            }
            else
            {
                TreeOfLife.Visibility = System.Windows.Visibility.Collapsed;
                colLeft.Width = new GridLength(0);
                colSplit.Width = new GridLength(0);
                CheckData.Visibility = System.Windows.Visibility.Collapsed;
                TuiData.Visibility = System.Windows.Visibility.Collapsed;
                FaBuData.Visibility = System.Windows.Visibility.Collapsed;
                tiaomu.Visibility = System.Windows.Visibility.Collapsed;
                JZXData.Visibility = System.Windows.Visibility.Collapsed;
                XDData.Visibility = System.Windows.Visibility.Collapsed;
                CancelCheckData.Visibility = System.Windows.Visibility.Collapsed;
                SuoData.Visibility = System.Windows.Visibility.Collapsed;
            }
        }

        private string islock = "0";
        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            nian.ItemsSource = null;
            islock = "1";
            ObservableCollection<PublicOfficialInfo> poi1 = new ObservableCollection<PublicOfficialInfo>();
            foreach (PublicOfficialInfo i in poi)
            {
               // if (i.Status == 3) poi1.Add(i);
                if (i.IsLocked.Value) poi1.Add(i);
            }
            if (poi1.Count > 0 && poi1[0] != null)
            {
                nian.ItemsSource = poi1;
                if (poi1.Count > 0) nian.SelectedIndex = 0;
            }
            Load();
            //Client1.GetPublicOfficialInfo1Completed += new EventHandler<GetPublicOfficialInfo1CompletedEventArgs>(Client1_GetPublicOfficialInfo1Completed);
            //Client1.GetPublicOfficialInfo1Async(0, DateTime.Today.Year - nian.SelectedIndex);
        }

        private void chkHiddenCols_Unchecked(object sender, RoutedEventArgs e)
        {
            nian.ItemsSource = null;
            islock = "0";
            ObservableCollection<PublicOfficialInfo> poi1 = new ObservableCollection<PublicOfficialInfo>();
            #region  old
            //foreach (PublicOfficialInfo p in poi)
            //{
            //    if (p.Status == 1) poi1.Add(p);
            //}
            //foreach (PublicOfficialInfo p in poi)
            //{
            //    if (p.Status == 2) poi1.Add(p);
            //}
            //foreach (PublicOfficialInfo p in poi)
            //{
            //    if (p.Status == 0) poi1.Add(p);
            //}
            #endregion
            foreach (PublicOfficialInfo p in poi)
            {
                // if (p.Status == 1 || p.Status == 0) poi1.Add(p);
                if (!p.IsLocked.Value) poi1.Add(p);
            }
            //if (poi.Where(p => p.Status == 1 || p.Status == 2).FirstOrDefault() != null) poi1.Add(poi.Where(p => p.Status == 1 || p.Status == 2).FirstOrDefault());
            if (poi1.Count > 0 && poi1[0] != null)
            {
                nian.ItemsSource = poi1;
                if (poi1.Count > 0) nian.SelectedIndex = 0;
            }
            else
            {
                nian.ItemsSource = null;
                ExamID = -1;
            }
            Load();
            //Client1.GetPublicOfficialInfo1Completed += new EventHandler<GetPublicOfficialInfo1CompletedEventArgs>(Client1_GetPublicOfficialInfo1Completed);
            //Client1.GetPublicOfficialInfo1Async(1, DateTime.Today.Year - nian.SelectedIndex);
        }

        #region 右键

        private readonly MouseClickManager _gridClickManagerXQ;
        private void dgXQ_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            e.Row.MouseLeftButtonUp += _gridClickManagerXQ.HandleClick;
            //右击小区
            RightMenuXQ(e);
        }

        private void RightMenuXQ(DataGridRowEventArgs e)
        {
            DataGridRow dgr = e.Row;
            PublicOfficialSelectionModel XQ = (PublicOfficialSelectionModel)dgr.DataContext;

            ContextMenu cm = new ContextMenu();
            System.Windows.Controls.MenuItem miUP = new System.Windows.Controls.MenuItem();
            miUP.Header = "编辑";
            miUP.Click += new RoutedEventHandler(miUP_Click);

            System.Windows.Controls.MenuItem miDE = new System.Windows.Controls.MenuItem();
            miDE.Header = "删除";
            miDE.Click += new RoutedEventHandler(miDE_Click);

            System.Windows.Controls.MenuItem miAdd = new System.Windows.Controls.MenuItem();
            miAdd.Header = "提交";
            miAdd.Click += new RoutedEventHandler(miAdd_Click);


            cm.Items.Add(miUP);
            cm.Items.Add(miDE);
            cm.Items.Add(miAdd);

            ContextMenuService.SetContextMenu(dgr, cm);
        }
        void miUP_Click(object sender, RoutedEventArgs e)
        {
            PublicOfficialSelectionModel selxq = ((System.Windows.Controls.MenuItem)sender).DataContext as PublicOfficialSelectionModel;

            if (selxq != null)
            {
                if (selxq.Status != 0 && selxq.Status != 2)
                {
                    SilverlightMessageBoxLibrary.Message.ErrorMessage("所选职位信息状态为不可编辑状态！");
                    return;
                }
                PublicOfficialSelectionWindow RMWindow = new PublicOfficialSelectionWindow(new List<string>(OrgID), false, selxq.ID, "", islock, ExamID, kaoshitype);
                RMWindow.Closed += new EventHandler(RMWindow_Closed);
                RMWindow.Show();

            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要编辑的职位信息！");
        }
        void miDE_Click(object sender, RoutedEventArgs e)
        {
            PublicOfficialSelectionModel selxq = ((System.Windows.Controls.MenuItem)sender).DataContext as PublicOfficialSelectionModel;

            if (selxq != null)
            {
                if (MessageBox.Show("确定删除吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    Client1.DetelePublicOfficialSelectionModelCompleted -=
                       new EventHandler<PublicOfficialSelectionService.DetelePublicOfficialSelectionModelCompletedEventArgs>(Client_DetelePublicOfficialSelectionModelCompleted);

                    Client1.DetelePublicOfficialSelectionModelCompleted +=
                        new EventHandler<PublicOfficialSelectionService.DetelePublicOfficialSelectionModelCompletedEventArgs>(Client_DetelePublicOfficialSelectionModelCompleted);
                    Client1.DetelePublicOfficialSelectionModelAsync("(" + selxq.ID.ToString() + ")");
                }

            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要删除的职位信息！");
        }
        void miAdd_Click(object sender, RoutedEventArgs e)
        {
            PublicOfficialSelectionModel selxq = ((System.Windows.Controls.MenuItem)sender).DataContext as PublicOfficialSelectionModel;

            if (selxq != null)
            {
                if (selxq.Status == 1 || selxq.Status == 3 || selxq.Status == 4)
                {
                    SilverlightMessageBoxLibrary.Message.ErrorMessage("所选职位信息状态为不可提交状态！");
                    return;
                }
                if (MessageBox.Show("确定提交吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    Client1.SavePublicOfficialSelectionModelCompleted -= new EventHandler<PublicOfficialSelectionService.SavePublicOfficialSelectionModelCompletedEventArgs>(Client1_SavePublicOfficialSelectionModelCompleted);
                    Client1.SavePublicOfficialSelectionModelCompleted += new EventHandler<PublicOfficialSelectionService.SavePublicOfficialSelectionModelCompletedEventArgs>(Client1_SavePublicOfficialSelectionModelCompleted);
                    Client1.SavePublicOfficialSelectionModelAsync("(" + selxq.ID.ToString() + ")");
                }

            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要提交的职位信息！");
        }
        private void _gridClickManagerXQ_DoubleClick(object sender, MouseButtonEventArgs e)
        {
            var selxq = this.DGRole.SelectedItem as PublicOfficialSelectionModel;
            if (selxq != null)
            {
                if (selxq.Status != 0 && selxq.Status != 2)
                {
                    SilverlightMessageBoxLibrary.Message.ErrorMessage("所选职位信息状态为不可编辑状态！");
                    return;
                }
                PublicOfficialSelectionWindow RMWindow = new PublicOfficialSelectionWindow(new List<string>(OrgID), false, selxq.ID, "", islock, ExamID, kaoshitype);
                RMWindow.Closed += new EventHandler(RMWindow_Closed);
                RMWindow.Show();

            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要编辑的职位信息！");
        }
        #endregion
        public void Load()
        {
            Client1.GetOrgIDbyDengLuRenCompleted -= new EventHandler<PublicOfficialSelectionService.GetOrgIDbyDengLuRenCompletedEventArgs>(Client_GetOrgIDbyDengLuRenCompleted);
            Client1.GetOrgIDbyDengLuRenCompleted += new EventHandler<PublicOfficialSelectionService.GetOrgIDbyDengLuRenCompletedEventArgs>(Client_GetOrgIDbyDengLuRenCompleted);
            Client1.GetOrgIDbyDengLuRenAsync(Session.LoginUser.UserID);
        }

        public void LoadData(string orgid)
        {
            //Client1.GetPublicOfficialSelectionCountCompleted -= new EventHandler<PublicOfficialSelectionService.GetPublicOfficialSelectionCountCompletedEventArgs>(Client1_GetPublicOfficialSelectionCountCompleted);
            //Client1.GetPublicOfficialSelectionCountCompleted += new EventHandler<PublicOfficialSelectionService.GetPublicOfficialSelectionCountCompletedEventArgs>(Client1_GetPublicOfficialSelectionCountCompleted);
            //Client1.GetPublicOfficialSelectionCountAsync(orgid, 0, Convert.ToInt32(((ComboBoxItem)status.SelectedItem).Tag), DateTime.Today.Year - nian.SelectedIndex, islock, ExamID);
            //Client1.GetPublicOfficialSelectionCompleted -= new EventHandler<PublicOfficialSelectionService.GetPublicOfficialSelectionCompletedEventArgs>(Client_GetPublicOfficialSelectionCompleted);
            //Client1.GetPublicOfficialSelectionCompleted += new EventHandler<PublicOfficialSelectionService.GetPublicOfficialSelectionCompletedEventArgs>(Client_GetPublicOfficialSelectionCompleted);
            //Client1.GetPublicOfficialSelectionAsync(orgid, 0, 0, 20, Convert.ToInt32(((ComboBoxItem)status.SelectedItem).Tag), DateTime.Today.Year - nian.SelectedIndex, islock, ExamID);
            //Client1.ChaKanShiFouDouShenHeCompleted -= new EventHandler<PublicOfficialSelectionService.ChaKanShiFouDouShenHeCompletedEventArgs>(Client1_ChaKanShiFouDouShenHeCompleted);
            //Client1.ChaKanShiFouDouShenHeCompleted += new EventHandler<PublicOfficialSelectionService.ChaKanShiFouDouShenHeCompletedEventArgs>(Client1_ChaKanShiFouDouShenHeCompleted);
            //Client1.ChaKanShiFouDouShenHeAsync(orgid, DateTime.Today.Year - nian.SelectedIndex,islock);
            Client1.GetPublicOfficialSelectionCountCompleted -= new EventHandler<PublicOfficialSelectionService.GetPublicOfficialSelectionCountCompletedEventArgs>(Client1_GetPublicOfficialSelectionCountCompleted);
            Client1.GetPublicOfficialSelectionCountCompleted += new EventHandler<PublicOfficialSelectionService.GetPublicOfficialSelectionCountCompletedEventArgs>(Client1_GetPublicOfficialSelectionCountCompleted);
            Client1.GetPublicOfficialSelectionCountAsync(orgid, 0, Convert.ToInt32(((ComboBoxItem)status.SelectedItem).Tag), 0, islock, ExamID);
            Client1.GetPublicOfficialSelectionCompleted -= new EventHandler<PublicOfficialSelectionService.GetPublicOfficialSelectionCompletedEventArgs>(Client_GetPublicOfficialSelectionCompleted);
            Client1.GetPublicOfficialSelectionCompleted += new EventHandler<PublicOfficialSelectionService.GetPublicOfficialSelectionCompletedEventArgs>(Client_GetPublicOfficialSelectionCompleted);
            Client1.GetPublicOfficialSelectionAsync(orgid, 0, 0, 20, Convert.ToInt32(((ComboBoxItem)status.SelectedItem).Tag), 0, islock, ExamID);
            Client1.ChaKanShiFouDouShenHeCompleted -= new EventHandler<PublicOfficialSelectionService.ChaKanShiFouDouShenHeCompletedEventArgs>(Client1_ChaKanShiFouDouShenHeCompleted);
            Client1.ChaKanShiFouDouShenHeCompleted += new EventHandler<PublicOfficialSelectionService.ChaKanShiFouDouShenHeCompletedEventArgs>(Client1_ChaKanShiFouDouShenHeCompleted);
            Client1.ChaKanShiFouDouShenHeAsync(orgid, ExamID, islock);
        }
        void Client1_ChaKanShiFouDouShenHeCompleted(object sender, PublicOfficialSelectionService.ChaKanShiFouDouShenHeCompletedEventArgs e)
        {
            if (e.Result != null)
                tiaomu.Text = "剩余" + e.Result + "条职位信息没有审核";
            else tiaomu.Text = "没有待审核的职位信息";
        }
        #region treeview
        void Client_GetOrgForHRModelCompleted(object sender, EmpbasicService.GetOrgForHRModelCompletedEventArgs e)
        {
            forumList.Clear();
            foreach (EmpbasicService.OrgForHRModel i in e.Result)
            {
                forumList.Add(i);
            }
            AddTreeNode("全部单位", null);
        }
        ObservableCollection<EmpbasicService.OrgForHRModel> forumList = new ObservableCollection<EmpbasicService.OrgForHRModel>();


        private void AddTreeNode(string type, TreeViewItem treeViewItem)
        {
            List<EmpbasicService.OrgForHRModel> result = (from forumInfo in forumList
                                                          where forumInfo.Type == type
                                                          select forumInfo).ToList<EmpbasicService.OrgForHRModel>();

            if (result.Count > 0)
            {
                foreach (EmpbasicService.OrgForHRModel foruminfo in result)
                {
                    TreeViewItem objTreeNode = new TreeViewItem();
                    CheckBox cb = new CheckBox();
                    cb.Content = foruminfo.Name;
                    cb.Tag = objTreeNode;
                    cb.DataContext = foruminfo;
                    //sp.Children.Add(cb);
                    cb.Click += new RoutedEventHandler(cb_Checked);
                    objTreeNode.Header = cb;
                    if ((objTreeNode.Header as CheckBox).Content.ToString() == "组织机构") objTreeNode.IsExpanded = true;
                    //添加根节点
                    if (treeViewItem == null)
                    {
                        TreeOfLife.Items.Add(objTreeNode);
                    }
                    else
                    {
                        treeViewItem.Items.Add(objTreeNode);
                    }
                    AddTreeNode(foruminfo.Name, objTreeNode);
                }
            }
        }
        void cb_Checked(object sender, RoutedEventArgs e)
        {
            CheckBox cb = sender as CheckBox;
            EmpbasicService.OrgForHRModel rm = cb.DataContext as EmpbasicService.OrgForHRModel;
            if (cb.IsChecked == true)
            {
                //if (orgids != null)
                //{
                //    OrgID = Convert.ToInt32(((EmpbasicService.OrgForHRModel)cb.DataContext).ID);
                //    LoadData(OrgID);
                //    //if (OrgID != 0 && OrgID != 79 && OrgID != 80 && OrgID != 81 && OrgID != 82 && OrgID != 83 && OrgID != 84)
                //    //{

                //    //}
                //}
                //else orgids.Add(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString());
                if (!orgids.Contains(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString()))
                    orgids.Add(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString());
                string ss = "";
                foreach (string i in orgids)
                    ss += i + ",";
                LoadData(ss.Substring(0, ss.Length - 1));
                //CheckParentItem(cb.Tag as TreeViewItem);
                CheckChildItem(cb.Tag as TreeViewItem);
            }
            else
            {
                if (orgids != null)
                {
                    if (orgids.Contains(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString()))
                        orgids.Remove(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString());
                }
                string ss = "";
                foreach (string i in orgids)
                    ss += i + ",";
                LoadData(ss.Substring(0, ss.Length - 1));
                UnCheckChildItem(cb.Tag as TreeViewItem);
            }
        }
        void CheckParentItem(TreeViewItem item)
        {
            TreeViewItem tvi = item.GetParentTreeViewItem();
            if (tvi != null)
            {
                CheckBox cb = tvi.Header as CheckBox;
                cb.IsChecked = true;
                CheckParentItem(tvi);
            }
        }
        public List<string> orgids = new List<string>();
        void CheckChildItem(TreeViewItem item)
        {
            foreach (TreeViewItem tvi in item.Items)
            {
                if (tvi != null)
                {
                    CheckBox cb = tvi.Header as CheckBox;
                    cb.IsChecked = true;
                    if (!orgids.Contains(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString()))
                        orgids.Add(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString());
                    CheckChildItem(tvi);
                }
            }
        }
        void UnCheckChildItem(TreeViewItem item)
        {
            foreach (TreeViewItem tvi in item.Items)
            {
                if (tvi != null)
                {
                    CheckBox cb = tvi.Header as CheckBox;
                    cb.IsChecked = false;
                    if (orgids.Contains(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString()))
                        orgids.Remove(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString());
                    UnCheckChildItem(tvi);
                }
            }
        }
        #endregion

        void Client_GetOrgIDbyDengLuRenCompleted(object sender, PublicOfficialSelectionService.GetOrgIDbyDengLuRenCompletedEventArgs e)
        {
            string[] ss = e.Result.Split(',');
            foreach (string i in ss)
            {
                Client1.GetTypebyOrgIDCompleted -= new EventHandler<PublicOfficialSelectionService.GetTypebyOrgIDCompletedEventArgs>(Client_GetTypebyOrgIDCompleted);
                Client1.GetTypebyOrgIDCompleted += new EventHandler<PublicOfficialSelectionService.GetTypebyOrgIDCompletedEventArgs>(Client_GetTypebyOrgIDCompleted);
                Client1.GetTypebyOrgIDAsync(Convert.ToInt32(i));
            }

        }

        void Client_GetTypebyOrgIDCompleted(object sender, PublicOfficialSelectionService.GetTypebyOrgIDCompletedEventArgs e)
        {
            if (e.Result != null)
            {
                foreach (string i in e.Result.Keys)
                {
                    //if (i != "参公系统")
                    //{
                    //OrgID = Convert.ToInt32(e.Result[i]);
                    if (!orgids.Contains(e.Result[i].ToString()))
                        orgids.Add(e.Result[i].ToString());
                    string ss = "";
                    foreach (string ii in orgids)
                        ss += ii + ",";
                    if (string.IsNullOrEmpty(ss)) ss = "0";
                    else ss = ss.Substring(0, ss.Length - 1);
                    Client1.ChaKanShiFouDouShenHeCompleted -= new EventHandler<PublicOfficialSelectionService.ChaKanShiFouDouShenHeCompletedEventArgs>(Client1_ChaKanShiFouDouShenHeCompleted);
                    Client1.ChaKanShiFouDouShenHeCompleted += new EventHandler<PublicOfficialSelectionService.ChaKanShiFouDouShenHeCompletedEventArgs>(Client1_ChaKanShiFouDouShenHeCompleted);
                    Client1.ChaKanShiFouDouShenHeAsync(ss, ExamID, islock);
                    Client1.GetPublicOfficialSelectionCountCompleted -= new EventHandler<PublicOfficialSelectionService.GetPublicOfficialSelectionCountCompletedEventArgs>(Client1_GetPublicOfficialSelectionCountCompleted);
                    Client1.GetPublicOfficialSelectionCountCompleted += new EventHandler<PublicOfficialSelectionService.GetPublicOfficialSelectionCountCompletedEventArgs>(Client1_GetPublicOfficialSelectionCountCompleted);
                    Client1.GetPublicOfficialSelectionCountAsync(ss, 0, Convert.ToInt32(((ComboBoxItem)status.SelectedItem).Tag), 0, islock, ExamID);
                    Client1.GetPublicOfficialSelectionCompleted -= new EventHandler<PublicOfficialSelectionService.GetPublicOfficialSelectionCompletedEventArgs>(Client_GetPublicOfficialSelectionCompleted);
                    Client1.GetPublicOfficialSelectionCompleted += new EventHandler<PublicOfficialSelectionService.GetPublicOfficialSelectionCompletedEventArgs>(Client_GetPublicOfficialSelectionCompleted);
                    Client1.GetPublicOfficialSelectionAsync(ss, 0, 0, 20, Convert.ToInt32(((ComboBoxItem)status.SelectedItem).Tag), 0, islock, ExamID);
                    //}

                }
            }

        }

        void Client1_GetPublicOfficialSelectionCountCompleted(object sender, PublicOfficialSelectionService.GetPublicOfficialSelectionCountCompletedEventArgs e)
        {
            int count = e.Result;
            ObservableCollection<int> source = new ObservableCollection<int>();
            for (int i = 0; i < count; i++)
            {
                source.Add(i + 1);

            }
            PagedCollectionView pcv = new PagedCollectionView(source);
            dataPager1.PageSize = 1;
            dataPager1.Source = pcv;
        }
        public ObservableCollection<PublicOfficialSelectionService.PublicOfficialSelectionModel> empmodel =
            new ObservableCollection<PublicOfficialSelectionService.PublicOfficialSelectionModel>();
        void Client_GetPublicOfficialSelectionCompleted(object sender, PublicOfficialSelectionService.GetPublicOfficialSelectionCompletedEventArgs e)
        {
            foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in e.Result)
            {
                if (empmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                {
                    empmodel.Add(i);
                }
            }
            foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in selectedempmodel)
            {
                if (e.Result.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == true)
                {
                    e.Result.Where(p => p.ID == i.ID).FirstOrDefault().IsSelected = true;
                }
            }
            tempJZXforall = e.Result;
            DGRole.ItemsSource = e.Result;
        }

        private void CheckBox_Click(object sender, RoutedEventArgs e)
        {
            CheckBox cb = sender as CheckBox;
            foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel p in DGRole.ItemsSource)
            {
                p.IsSelected = (bool)cb.IsChecked;
                //CheckBox cb1 = DGRole.Columns[0].GetCellContent(p) as CheckBox;
                //cb1.IsChecked = p.IsSelected;
                if (p.IsSelected)
                {
                    if (selectedempmodel.Where(i => i.ID == p.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(p);
                    }
                }
                else
                {
                    if (selectedempmodel.Where(i => i.ID == p.ID).FirstOrDefault() != null)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(i => i.ID == p.ID).FirstOrDefault());
                    }
                }
            }

        }
        #region 操作
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NewData_Click(object sender, RoutedEventArgs e)
        {
            //if (orgids.Count > 1)
            //{
            //    SilverlightMessageBoxLibrary.Message.ErrorMessage("只能针对一个单位进行职位信息的新增！"); 
            //    return;
            //}
            if (kaoshistatus != 2)
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("所选考试状态不可进行职位新增操作！");
                return;
            }
            PublicOfficialSelectionWindow RMWindow = new PublicOfficialSelectionWindow(orgids, true, 0, "", islock, ExamID, kaoshitype);
            RMWindow.Closed += new EventHandler(RMWindow_Closed);
            RMWindow.Show();
        }
        void RMWindow_Closed(object sender, EventArgs e)
        {
            Load();
        }

        private void EditData_Click(object sender, RoutedEventArgs e)
        {
            //if (orgids.Count > 1)
            //{
            //    SilverlightMessageBoxLibrary.Message.ErrorMessage("只能针对一个单位进行职位信息的编辑！");
            //    return;
            //}
            if (kaoshistatus != 2)
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("所选考试状态不可进行职位编辑操作！");
                return;
            }
            selectedempmodel.Clear();
            if (DGRole.ItemsSource != null)
            {
                foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in (ObservableCollection<PublicOfficialSelectionService.PublicOfficialSelectionModel>)DGRole.ItemsSource)
                {
                    if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(i);
                    }
                    if (selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == false)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
                    }
                }
            }
            if (selectedempmodel.Count > 0)
            {
                foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in selectedempmodel)
                {
                    if (juese == "人事干部" && (i.Status == 1 || i.Status == 3 || i.Status == 4))
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage("所选职位信息状态为不可编辑状态！");
                        return;
                    }
                    if (i.IsLocked == true)
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage("所选职位信息状态为不可编辑状态！");
                        return;
                    }
                }
                if (selectedempmodel.Count > 1)
                {
                    SilverlightMessageBoxLibrary.Message.ErrorMessage("只能选择一条职位信息进行编辑！");
                    return;
                }
                PublicOfficialSelectionWindow RMWindow = new PublicOfficialSelectionWindow(orgids, false, selectedempmodel[0].ID, "", islock, ExamID, kaoshitype);
                RMWindow.Closed += new EventHandler(RMWindow_Closed);
                RMWindow.Show();

            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要编辑的职位信息！");
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteData_Click(object sender, RoutedEventArgs e)
        {
            if (kaoshistatus != 2)
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("所选考试状态不可进行职位删除操作！");
                return;
            }
            selectedempmodel.Clear();
            if (DGRole.ItemsSource != null)
            {
                foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in (ObservableCollection<PublicOfficialSelectionService.PublicOfficialSelectionModel>)DGRole.ItemsSource)
                {
                    if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(i);
                    }
                    if (selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == false)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
                    }
                }
            }
            if (selectedempmodel.Count > 0)
            {
                foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in selectedempmodel)
                {
                    if (juese != "人事干部" && i.Status == 1)
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage("所选职位信息状态为不可删除状态！");
                        return;
                    }
                    if (juese != "人事干部" && i.Status == 3)
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage("所选职位信息状态为不可删除状态！");
                        return;
                    }
                    if (juese != "人事干部" && i.Status == 4)
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage("所选职位信息状态为不可删除状态！");
                        return;
                    }
                    if (juese == "人事干部" && (i.Status == 1 || i.Status == 3 || i.Status == 4))
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage("所选职位信息状态为不可删除状态！");
                        return;
                    }
                    if (i.IsLocked == true)
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage("所选职位信息状态为不可删除状态！");
                        return;
                    }
                }
                if (MessageBox.Show("确定删除吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    string ids = "";

                    foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in selectedempmodel)
                    {
                        ids += i.ID.ToString() + ",";
                    }

                    Client1.DetelePublicOfficialSelectionModelCompleted -=
                       new EventHandler<PublicOfficialSelectionService.DetelePublicOfficialSelectionModelCompletedEventArgs>(Client_DetelePublicOfficialSelectionModelCompleted);

                    Client1.DetelePublicOfficialSelectionModelCompleted +=
                        new EventHandler<PublicOfficialSelectionService.DetelePublicOfficialSelectionModelCompletedEventArgs>(Client_DetelePublicOfficialSelectionModelCompleted);
                    Client1.DetelePublicOfficialSelectionModelAsync("(" + ids.Substring(0, ids.Length - 1) + ")");
                }

            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要删除的职位信息！");
        }

        void Client_DetelePublicOfficialSelectionModelCompleted(object sender, PublicOfficialSelectionService.DetelePublicOfficialSelectionModelCompletedEventArgs e)
        {
            SilverlightMessageBoxLibrary.Message.InfoMessage("删除成功！");
            Load();
        }
        private void ViewData_Click(object sender, RoutedEventArgs e)
        {
            if (DGRole.ItemsSource != null)
            {
                foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in (ObservableCollection<PublicOfficialSelectionService.PublicOfficialSelectionModel>)DGRole.ItemsSource)
                {
                    if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(i);
                    }
                    if (selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == false)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
                    }
                }
            }
            if (selectedempmodel.Count > 0)
            {
                if (selectedempmodel.Count > 1)
                {
                    SilverlightMessageBoxLibrary.Message.ErrorMessage("只能选择一条职位信息进行查看！");
                    return;
                }
                PublicOfficialSelectionWindow RMWindow = new PublicOfficialSelectionWindow(orgids, false, selectedempmodel[0].ID, "查看", islock, ExamID, kaoshitype);
                RMWindow.Closed += new EventHandler(RMWindow_Closed);
                RMWindow.Show();

            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要查看的职位信息！");
        }
        private void SaveData_Click(object sender, RoutedEventArgs e)
        {
            if (kaoshistatus != 2)
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("所选考试状态不可进行职位提交操作！");
                return;
            }
            selectedempmodel.Clear();
            if (DGRole.ItemsSource != null)
            {
                foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in (ObservableCollection<PublicOfficialSelectionService.PublicOfficialSelectionModel>)DGRole.ItemsSource)
                {
                    if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(i);
                    }
                    if (selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == false)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
                    }
                }
            }
            if (selectedempmodel.Count > 0)
            {
                foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in selectedempmodel)
                {
                    if (i.Status == 1 || i.Status == 3 || i.Status == 4 || i.IsLocked == true)
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage("所选职位信息状态为不可提交状态！");
                        return;
                    }
                }
                if (MessageBox.Show("确定提交吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    string ids = "";

                    foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in selectedempmodel)
                    {
                        ids += i.ID.ToString() + ",";
                    }
                    Client1.SavePublicOfficialSelectionModelCompleted -= new EventHandler<PublicOfficialSelectionService.SavePublicOfficialSelectionModelCompletedEventArgs>(Client1_SavePublicOfficialSelectionModelCompleted);
                    Client1.SavePublicOfficialSelectionModelCompleted += new EventHandler<PublicOfficialSelectionService.SavePublicOfficialSelectionModelCompletedEventArgs>(Client1_SavePublicOfficialSelectionModelCompleted);
                    Client1.SavePublicOfficialSelectionModelAsync("(" + ids.Substring(0, ids.Length - 1) + ")");
                }

            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要提交的职位信息！");
        }

        private void CheckData_Click(object sender, RoutedEventArgs e)
        {
            if (kaoshistatus != 2)
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("所选考试状态不可进行职位审核通过操作！");
                return;
            }
            selectedempmodel.Clear();
            if (DGRole.ItemsSource != null)
            {
                foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in (ObservableCollection<PublicOfficialSelectionService.PublicOfficialSelectionModel>)DGRole.ItemsSource)
                {
                    if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(i);
                    }
                    if (selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == false)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
                    }
                }
            }
            if (selectedempmodel.Count > 0)
            {
                foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in selectedempmodel)
                {
                    if (i.Status == 0 || i.Status == 2 || i.Status == 3 || i.Status == 4 || i.IsLocked == true)
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage("所选职位信息状态为不可审核状态！");
                        return;
                    }
                }
                if (MessageBox.Show("确定通过审核吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    string ids = "";

                    foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in selectedempmodel)
                    {
                        ids += i.ID.ToString() + ",";
                    }
                    Client1.CheckPublicOfficialSelectionModelCompleted -=
                        new EventHandler<PublicOfficialSelectionService.CheckPublicOfficialSelectionModelCompletedEventArgs>(Client1_CheckPublicOfficialSelectionModelCompleted);
                    Client1.CheckPublicOfficialSelectionModelCompleted +=
                        new EventHandler<PublicOfficialSelectionService.CheckPublicOfficialSelectionModelCompletedEventArgs>(Client1_CheckPublicOfficialSelectionModelCompleted);
                    Client1.CheckPublicOfficialSelectionModelAsync("(" + ids.Substring(0, ids.Length - 1) + ")");
                }

            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要通过审核的职位信息！");
        }

        void Client1_CheckPublicOfficialSelectionModelCompleted(object sender, PublicOfficialSelectionService.CheckPublicOfficialSelectionModelCompletedEventArgs e)
        {
            SilverlightMessageBoxLibrary.Message.InfoMessage("审核成功！");
            Load();
        }

        private void TuiData_Click(object sender, RoutedEventArgs e)
        {
            if (kaoshistatus != 2)
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("所选考试状态不可进行职位退回操作！");
                return;
            }
            selectedempmodel.Clear();
            if (DGRole.ItemsSource != null)
            {
                foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in (ObservableCollection<PublicOfficialSelectionService.PublicOfficialSelectionModel>)DGRole.ItemsSource)
                {
                    if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(i);
                    }
                    if (selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == false)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
                    }
                }
            }
            if (selectedempmodel.Count > 0)
            {
                foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in selectedempmodel)
                {
                    if (i.Status == 0 || i.Status == 2 || i.Status == 4 || i.IsLocked == true)
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage("所选职位信息状态为不可退回状态！");
                        return;
                    }
                }
                TuiHuiMemoWindow tuihui = new TuiHuiMemoWindow();
                tuihui.Closed += new EventHandler(tuihui_Closed);
                tuihui.Show();
            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要退回的职位信息！");
        }

        void tuihui_Closed(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定退回吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                string ids = "";

                foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in selectedempmodel)
                {
                    ids += i.ID.ToString() + ",";
                }
                Client1.TuiPublicOfficialSelectionModelCompleted -= new EventHandler<PublicOfficialSelectionService.TuiPublicOfficialSelectionModelCompletedEventArgs>(Client1_TuiPublicOfficialSelectionModelCompleted);
                Client1.TuiPublicOfficialSelectionModelCompleted += new EventHandler<PublicOfficialSelectionService.TuiPublicOfficialSelectionModelCompletedEventArgs>(Client1_TuiPublicOfficialSelectionModelCompleted);
                Client1.TuiPublicOfficialSelectionModelAsync("(" + ids.Substring(0, ids.Length - 1) + ")", ((TuiHuiMemoWindow)sender).checkmemo);
            }
        }

        void Client1_TuiPublicOfficialSelectionModelCompleted(object sender, PublicOfficialSelectionService.TuiPublicOfficialSelectionModelCompletedEventArgs e)
        {
            SilverlightMessageBoxLibrary.Message.InfoMessage("退回成功！");
            Load();
        }

        void Client1_SavePublicOfficialSelectionModelCompleted(object sender, PublicOfficialSelectionService.SavePublicOfficialSelectionModelCompletedEventArgs e)
        {
            SilverlightMessageBoxLibrary.Message.InfoMessage("提交成功！");
            Load();
        }

        private void ChaData_Click(object sender, RoutedEventArgs e)
        {
            string ss = "";
            foreach (string ii in orgids)
                ss += ii + ",";
            if (string.IsNullOrEmpty(ss)) ss = "0";
            else ss = ss.Substring(0, ss.Length - 1);
            Client1.ChaKanShiFouDouShenHeCompleted -= new EventHandler<PublicOfficialSelectionService.ChaKanShiFouDouShenHeCompletedEventArgs>(Client1_ChaKanShiFouDouShenHeCompleted);
            Client1.ChaKanShiFouDouShenHeCompleted += new EventHandler<PublicOfficialSelectionService.ChaKanShiFouDouShenHeCompletedEventArgs>(Client1_ChaKanShiFouDouShenHeCompleted);
            Client1.ChaKanShiFouDouShenHeAsync(ss, ExamID, islock);
            Client1.GetPublicOfficialSelectionCountCompleted += new EventHandler<PublicOfficialSelectionService.GetPublicOfficialSelectionCountCompletedEventArgs>(Client1_GetPublicOfficialSelectionCountCompleted);
            Client1.GetPublicOfficialSelectionCountAsync(ss, 0, Convert.ToInt32(((ComboBoxItem)status.SelectedItem).Tag), 0, islock, ExamID);
            Client1.GetPublicOfficialSelectionCompleted += new EventHandler<PublicOfficialSelectionService.GetPublicOfficialSelectionCompletedEventArgs>(Client_GetPublicOfficialSelectionCompleted);
            Client1.GetPublicOfficialSelectionAsync(ss, 0, 0, 20, Convert.ToInt32(((ComboBoxItem)status.SelectedItem).Tag), 0, islock, ExamID);
        }

        private void FaBuData_Click(object sender, RoutedEventArgs e)
        {
            if (kaoshistatus != 2)
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("所选考试状态不可进行职位发布操作！");
                return;
            }
            selectedempmodel.Clear();
            if (DGRole.ItemsSource != null)
            {
                foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in (ObservableCollection<PublicOfficialSelectionService.PublicOfficialSelectionModel>)DGRole.ItemsSource)
                {
                    if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(i);
                    }
                    if (selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == false)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
                    }
                }
            }
            if (selectedempmodel.Count > 0)
            {
                foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in selectedempmodel)
                {
                    if (i.Status != 3 || i.IsLocked == true)
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage("所选职位信息状态为不可发布状态！");
                        return;
                    }
                }
                if (MessageBox.Show("确定发布吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    PublicOfficialSelectionFaBuType tuihui = new PublicOfficialSelectionFaBuType();
                    tuihui.Closed += new EventHandler(PublicOfficialSelectionFaBuType_Closed);
                    tuihui.Show();

                }

            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要发布的职位信息！");
        }
        void PublicOfficialSelectionFaBuType_Closed(object sender, EventArgs e)
        {
            if (((PublicOfficialSelectionFaBuType)sender).DialogResult == true)
            {
                string ids = "";
                foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in selectedempmodel)
                {
                    ids += i.ID.ToString() + ",";
                }
                Client1.FaBuPublicOfficialSelectionModelCompleted -= new EventHandler<PublicOfficialSelectionService.FaBuPublicOfficialSelectionModelCompletedEventArgs>(Client1_FaBuPublicOfficialSelectionModelCompleted);
                Client1.FaBuPublicOfficialSelectionModelCompleted += new EventHandler<PublicOfficialSelectionService.FaBuPublicOfficialSelectionModelCompletedEventArgs>(Client1_FaBuPublicOfficialSelectionModelCompleted);
                Client1.FaBuPublicOfficialSelectionModelAsync("(" + ids.Substring(0, ids.Length - 1) + ")", ((PublicOfficialSelectionFaBuType)sender).fabutype);
            }

        }
        private void btnSuoData_Click(object sender, RoutedEventArgs e)
        {
            //selectedempmodel.Clear();
            //if (DGRole.ItemsSource != null)
            //{
            //    foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in (ObservableCollection<PublicOfficialSelectionService.PublicOfficialSelectionModel>)DGRole.ItemsSource)
            //    {
            //        if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
            //        {
            //            selectedempmodel.Add(i);
            //        }
            //        if (selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == false)
            //        {
            //            selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
            //        }
            //    }
            //}
            //if (selectedempmodel.Count > 0)
            //{
            if (MessageBox.Show("确定锁定本期工作吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                Client1.SuoPublicOfficialSelectionCompleted -= new EventHandler<SuoPublicOfficialSelectionCompletedEventArgs>(Client1_SuoPublicOfficialSelectionCompleted);
                Client1.SuoPublicOfficialSelectionCompleted += new EventHandler<SuoPublicOfficialSelectionCompletedEventArgs>(Client1_SuoPublicOfficialSelectionCompleted);
                Client1.SuoPublicOfficialSelectionAsync(ExamID);
            }

            //}
            //else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要发布的职位信息！");
        }

        void Client1_SuoPublicOfficialSelectionCompleted(object sender, SuoPublicOfficialSelectionCompletedEventArgs e)
        {
            SilverlightMessageBoxLibrary.Message.InfoMessage("锁定成功！");
            Load();
        }
        private void CancelCheckData_Click(object sender, RoutedEventArgs e)
        {
            if (kaoshistatus != 2)
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("所选考试状态不可进行职位撤销审核操作！");
                return;
            }
            selectedempmodel.Clear();
            if (DGRole.ItemsSource != null)
            {
                foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in (ObservableCollection<PublicOfficialSelectionService.PublicOfficialSelectionModel>)DGRole.ItemsSource)
                {
                    if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(i);
                    }
                    if (selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == false)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
                    }
                }
            }
            if (selectedempmodel.Count > 0)
            {
                foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in selectedempmodel)
                {
                    if (i.Status != 3 || i.IsLocked == true)
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage("所选职位信息状态不为已审核，不可取消审核！");
                        return;
                    }
                }
                if (MessageBox.Show("确定取消审核吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    string ids = "";

                    foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in selectedempmodel)
                    {
                        ids += i.ID.ToString() + ",";
                    }
                    Client1.CancelPublicOfficialSelectionModelCompleted -= new EventHandler<CancelPublicOfficialSelectionModelCompletedEventArgs>(Client1_CancelPublicOfficialSelectionModelCompleted);
                    Client1.CancelPublicOfficialSelectionModelCompleted += new EventHandler<CancelPublicOfficialSelectionModelCompletedEventArgs>(Client1_CancelPublicOfficialSelectionModelCompleted);
                    Client1.CancelPublicOfficialSelectionModelAsync("(" + ids.Substring(0, ids.Length - 1) + ")");
                }

            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要发布的职位信息！");
        }

        void Client1_CancelPublicOfficialSelectionModelCompleted(object sender, CancelPublicOfficialSelectionModelCompletedEventArgs e)
        {
            SilverlightMessageBoxLibrary.Message.InfoMessage("取消审核成功！");
            Load();
        }

        void Client1_FaBuPublicOfficialSelectionModelCompleted(object sender, PublicOfficialSelectionService.FaBuPublicOfficialSelectionModelCompletedEventArgs e)
        {
            SilverlightMessageBoxLibrary.Message.InfoMessage("发布成功！");
            Load();
        }
        #endregion
        #region 左右拖动的条
        private GridLength _lastColLeftLength;
        private GridLength _lastColRightLength;
        private void GridSpliteTo_ToLeft(object sender, EventArgs e)
        {
            //已经到最左边，直接返回
            if (colLeft.Width.Value == 0.0)
            {
                return;
            }

            //
            if (colRight.Width.Value == 0)
            {
                colLeft.Width = _lastColLeftLength;
                colRight.Width = _lastColRightLength;
            }
            else
            {
                _lastColLeftLength = colLeft.Width;
                _lastColRightLength = colRight.Width;

                colLeft.Width = new GridLength(0);
                colRight.Width = new GridLength(150, GridUnitType.Star);
            }
        }

        private void GridSpliteTo_ToRight(object sender, EventArgs e)
        {
            if (colRight.Width.Value == 0)
            {
                return;
            }

            if (colLeft.Width.Value == 0)
            {
                colLeft.Width = _lastColLeftLength;
                colRight.Width = _lastColRightLength;
            }
            else
            {
                _lastColLeftLength = colLeft.Width;
                _lastColRightLength = colRight.Width;

                colRight.Width = new GridLength(0);
                colLeft.Width = new GridLength(300, GridUnitType.Star);
            }
        }
        #endregion
        #region 翻页
        private void dataPager1_PageIndexChanged(object sender, EventArgs e)
        {
            int index = dataPager1.PageIndex;
            string ss = "";
            foreach (string ii in orgids)
                ss += ii + ",";
            if (DGRole.ItemsSource != null)
            {
                foreach (PublicOfficialSelectionService.PublicOfficialSelectionModel i in (ObservableCollection<PublicOfficialSelectionService.PublicOfficialSelectionModel>)DGRole.ItemsSource)
                {
                    if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(i);
                    }
                    if (selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == false)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
                    }
                }
            }
            if (string.IsNullOrEmpty(ss)) ss = "0";
            else ss = ss.Substring(0, ss.Length - 1);
            Client1.GetPublicOfficialSelectionCompleted -= new EventHandler<PublicOfficialSelectionService.GetPublicOfficialSelectionCompletedEventArgs>(Client_GetPublicOfficialSelectionCompleted);
            Client1.GetPublicOfficialSelectionCompleted += new EventHandler<PublicOfficialSelectionService.GetPublicOfficialSelectionCompletedEventArgs>(Client_GetPublicOfficialSelectionCompleted);
            Client1.GetPublicOfficialSelectionAsync(ss, 0, index * 20, index * 20 + 20, Convert.ToInt32(((ComboBoxItem)status.SelectedItem).Tag), 0, islock, ExamID);
            //Client1.GetPublicOfficialSelectionCountCompleted -= new EventHandler<PublicOfficialSelectionService.GetPublicOfficialSelectionCountCompletedEventArgs>(Client1_GetPublicOfficialSelectionCountCompleted);
            //Client1.GetPublicOfficialSelectionCountCompleted += new EventHandler<PublicOfficialSelectionService.GetPublicOfficialSelectionCountCompletedEventArgs>(Client1_GetPublicOfficialSelectionCountCompleted);
            //Client1.GetPublicOfficialSelectionCountAsync(ss, 0, Convert.ToInt32(((ComboBoxItem)status.SelectedItem).Tag), DateTime.Today.Year - nian.SelectedIndex, islock);
        }
        #endregion

        #region 导出
        private Stream ss = null;
        private ObservableCollection<PublicOfficialSelectionService.PublicOfficialSelectionModel> tempJZXforall =
            new ObservableCollection<PublicOfficialSelectionService.PublicOfficialSelectionModel>();
        private ObservableCollection<PublicOfficialSelectionService.PublicOfficialSelectionModel> tempJZXforall1 =
            new ObservableCollection<PublicOfficialSelectionService.PublicOfficialSelectionModel>();
        private string sy = "";
        private void btnJZXOut_Click(object sender, RoutedEventArgs e)
        {
            tempJZXforall1.Clear();
            tempJZXforall1 = new ObservableCollection<PublicOfficialSelectionModel>(tempJZXforall.Where(p => p.IsJZXXB == true));
            sy = "竞争性选拔";
            ss = null;
            var downLoad = new SaveFileDialog()
            {
                //Filter = "Excel files(2007~2010) (*.xlsx)|*.xlsx|Excel files(2003) (*.xls)|*.xls", //"Excel files (*.xlsx)|*.xlsx|(*.xls)|*.xls",
                Filter = "Excel files(2003) (*.xls)|*.xls",
            };
            if (downLoad.ShowDialog() == true)
            {
                ss = downLoad.OpenFile();
                PageInit();
                //Client1.GetPublicOfficialSelectionForDaoChuCompleted -= new EventHandler<GetPublicOfficialSelectionForDaoChuCompletedEventArgs>(Client1_GetPublicOfficialSelectionForDaoChuCompleted);
                //Client1.GetPublicOfficialSelectionForDaoChuCompleted += new EventHandler<GetPublicOfficialSelectionForDaoChuCompletedEventArgs>(Client1_GetPublicOfficialSelectionForDaoChuCompleted);
                //Client1.GetPublicOfficialSelectionForDaoChuAsync("竞争性选拔", DateTime.Today.Year - nian.SelectedIndex, islock, ExamID, ss);

            }
        }

        private void btnXDOut_Click(object sender, RoutedEventArgs e)
        {
            tempJZXforall1.Clear();
            tempJZXforall1 = new ObservableCollection<PublicOfficialSelectionModel>(tempJZXforall.Where(p => p.IsXDJL == true));
            ss = null;
            sy = "选调交流";
            var downLoad = new SaveFileDialog()
            {
                //Filter = "Excel files(2007~2010) (*.xlsx)|*.xlsx|Excel files(2003) (*.xls)|*.xls", //"Excel files (*.xlsx)|*.xlsx|(*.xls)|*.xls",
                Filter = "Excel files(2003) (*.xls)|*.xls",
            };
            if (downLoad.ShowDialog() == true)
            {
                ss = downLoad.OpenFile();
                //Client1.GetPublicOfficialSelectionForDaoChuCompleted -= new EventHandler<GetPublicOfficialSelectionForDaoChuCompletedEventArgs>(Client1_GetPublicOfficialSelectionForDaoChuCompleted);
                //Client1.GetPublicOfficialSelectionForDaoChuCompleted += new EventHandler<GetPublicOfficialSelectionForDaoChuCompletedEventArgs>(Client1_GetPublicOfficialSelectionForDaoChuCompleted);
                //Client1.GetPublicOfficialSelectionForDaoChuAsync("选调交流", DateTime.Today.Year - nian.SelectedIndex, islock, ExamID, ss);
                PageInit();

            }
        }

        //void Client1_GetPublicOfficialSelectionForDaoChuCompleted(object sender, GetPublicOfficialSelectionForDaoChuCompletedEventArgs e)
        //{
        //    ss = e.UserState as Stream;
        //    tempJZXforall = e.Result;
        //    PageInit();
        //}

        public void PageInit()
        {
            XlsDocument xls = new XlsDocument();
            XF xf = xls.NewXF();
            xf.HorizontalAlignment = HorizontalAlignments.Centered;
            xf.VerticalAlignment = VerticalAlignments.Centered;
            xf.UseBorder = true;
            xf.TopLineStyle = 1;
            xf.TopLineColor = org.in2bits.MyXls.Colors.Black;
            xf.BottomLineStyle = 1;
            xf.BottomLineColor = org.in2bits.MyXls.Colors.Black;
            xf.LeftLineStyle = 1;
            xf.LeftLineColor = org.in2bits.MyXls.Colors.Black;
            xf.RightLineStyle = 1;
            xf.RightLineColor = org.in2bits.MyXls.Colors.Black;

            XF xf1 = xls.NewXF();
            xf1.UseBorder = true;
            xf1.TopLineStyle = 1;
            xf1.TopLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.BottomLineStyle = 1;
            xf1.BottomLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.LeftLineStyle = 1;
            xf1.LeftLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.RightLineStyle = 1;
            xf1.RightLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.HorizontalAlignment = HorizontalAlignments.Centered;
            xf1.VerticalAlignment = VerticalAlignments.Centered;
            xf1.Font.Bold = true;
            xf1.Font.Height = 15 * 20;

            XF xf3 = xls.NewXF();
            xf3.UseBorder = true;
            xf3.TopLineStyle = 1;
            xf3.TopLineColor = org.in2bits.MyXls.Colors.Black;
            xf3.BottomLineStyle = 1;
            xf3.BottomLineColor = org.in2bits.MyXls.Colors.Black;
            xf3.LeftLineStyle = 1;
            xf3.LeftLineColor = org.in2bits.MyXls.Colors.Black;
            xf3.RightLineStyle = 1;
            xf3.RightLineColor = org.in2bits.MyXls.Colors.Black;
            xf3.HorizontalAlignment = HorizontalAlignments.Centered;
            xf3.VerticalAlignment = VerticalAlignments.Centered;
            xf3.Font.Bold = true;
            xf3.Font.Height = 12 * 20;

            Worksheet sheet1 = null;
            if (sy == "竞争性选拔")
            {
                sheet1 = xls.Workbook.Worksheets.AddNamed("竞争性选拔岗位申报表");
                sheet1.Cells.Merge(1, 1, 1, 10);
                sheet1.Cells.Add(1, 1, "徐汇区" + DateTime.Today.Year + "年科级及科以下公务员竞争性选拔岗位申报表", xf1);
            }
            if (sy == "选调交流")
            {
                sheet1 = xls.Workbook.Worksheets.AddNamed("选调交流岗位申报表");
                sheet1.Cells.Merge(1, 1, 1, 10);
                sheet1.Cells.Add(1, 1, "徐汇区" + DateTime.Today.Year + "年科级及科以下公务员选调交流岗位申报表", xf1);
            }
            sheet1.Cells.Add(2, 1, "序号", xf3);
            sheet1.Cells.Add(2, 2, "单位", xf3);
            sheet1.Cells.Add(2, 3, "部门", xf3);
            sheet1.Cells.Add(2, 4, "科室", xf3);
            sheet1.Cells.Add(2, 5, "职位", xf3);
            sheet1.Cells.Add(2, 6, "职位简介", xf3);
            sheet1.Cells.Add(2, 7, "人数", xf3);
            sheet1.Cells.Add(2, 8, "文化程度", xf3);
            sheet1.Cells.Add(2, 9, "政治面貌", xf3);
            sheet1.Cells.Add(2, 10, "职位资格条件", xf3);
            sheet1.Cells.Add(2, 11, "备注", xf3);

            ColumnInfo colInfoxueli1 = new ColumnInfo(xls, sheet1);
            colInfoxueli1.Width = 40 * 256;
            colInfoxueli1.ColumnIndexStart = 2;
            colInfoxueli1.ColumnIndexEnd = 2;
            sheet1.AddColumnInfo(colInfoxueli1);
            ColumnInfo colInfoxueli2 = new ColumnInfo(xls, sheet1);
            colInfoxueli2.Width = 20 * 256;
            colInfoxueli2.ColumnIndexStart = 3;
            colInfoxueli2.ColumnIndexEnd = 3;
            sheet1.AddColumnInfo(colInfoxueli2);

            ColumnInfo colInfoxueli3 = new ColumnInfo(xls, sheet1);
            colInfoxueli3.Width = 30 * 256;
            colInfoxueli3.ColumnIndexStart = 4;
            colInfoxueli3.ColumnIndexEnd = 4;
            sheet1.AddColumnInfo(colInfoxueli3);
            ColumnInfo colInfoxueli6 = new ColumnInfo(xls, sheet1);
            colInfoxueli6.Width = 40 * 256;
            colInfoxueli6.ColumnIndexStart = 5;
            colInfoxueli6.ColumnIndexEnd = 5;
            sheet1.AddColumnInfo(colInfoxueli6);
            ColumnInfo colInfoxueli7 = new ColumnInfo(xls, sheet1);
            colInfoxueli7.Width = 30 * 256;
            colInfoxueli7.ColumnIndexStart = 9;
            colInfoxueli7.ColumnIndexEnd = 9;
            sheet1.AddColumnInfo(colInfoxueli7);
            //填充内容    
            if (tempJZXforall.Count > 0)
                for (int i = 0; i < tempJZXforall.Count; i++)
                {
                    sheet1.Cells.Add(i + 3, 1, i + 1, xf);
                    if (tempJZXforall[i].OrgName != null) sheet1.Cells.Add(i + 3, 3, tempJZXforall[i].OrgName.ToString(), xf);
                    if (tempJZXforall[i].Department != null) sheet1.Cells.Add(i + 3, 2, tempJZXforall[i].Department.ToString(), xf);
                    if (tempJZXforall[i].Department_Duty != null) sheet1.Cells.Add(i + 3, 4, tempJZXforall[i].Department_Duty.ToString(), xf);
                    if (tempJZXforall[i].Duty != null) sheet1.Cells.Add(i + 3, 5, tempJZXforall[i].Duty.ToString(), xf);
                    if (tempJZXforall[i].DutyDescription != null) sheet1.Cells.Add(i + 3, 6, tempJZXforall[i].DutyDescription.ToString(), xf);
                    if (tempJZXforall[i].PeopleCount != null) sheet1.Cells.Add(i + 3, 7, tempJZXforall[i].PeopleCount.ToString(), xf);
                    if (tempJZXforall[i].Education != null) sheet1.Cells.Add(i + 3, 8, tempJZXforall[i].Education.ToString(), xf);
                    if (tempJZXforall[i].Political != null) sheet1.Cells.Add(i + 3, 9, tempJZXforall[i].Political.ToString(), xf);
                    if (tempJZXforall[i].DutyQualifications != null) sheet1.Cells.Add(i + 3, 10, tempJZXforall[i].DutyQualifications.ToString(), xf);
                    if (tempJZXforall[i].Memo != null) sheet1.Cells.Add(i + 3, 11, tempJZXforall[i].Memo.ToString(), xf);
                }
            xls.Save(ss);
            ss.Close();
            ss.Dispose();
            SilverlightMessageBoxLibrary.Message.InfoMessage("导出成功！");
        }
        #endregion
    }
}
    